class CodeGenerator {
  constructor(aiGenerator) {
    this.aiGenerator = aiGenerator;
  }

  processAIResponse(response) {
    // 提取代码块
    const codeMatch = response.match(/```html\n([\s\S]+?)\n```/);
    if (!codeMatch) {
      console.warn('No code block found in AI response');
      return null;
    }
    
    const code = codeMatch[1];
    
    // 提取template、style和script部分
    const templateMatch = /<template>([\s\S]+?)<\/template>/;
    const styleMatch = /<style>([\s\S]+?)<\/style>/;
    const scriptMatch = /<script>([\s\S]+?)<\/script>/;
    
    const template = (code.match(templateMatch) || [])[1] || '';
    const style = (code.match(styleMatch) || [])[1] || '';
    const script = (code.match(scriptMatch) || [])[1] || '';
    
    // 直接返回组装后的代码，不需要额外转换
    return this.generateUXCode(template.trim(), style.trim(), script.trim());
  }

  generateUXCode(template, style, script) {
    return `<template>${template}</template>

<style>${style}</style>

<script>${script}</script>`;
  }
}

module.exports = CodeGenerator; 